// router.js
import { createRouter as _createRouter, createMemoryHistory, createWebHistory } from 'vue-router'

import Home from '../views/Home.vue'
import About from '../views/About.vue'
import AddOrEdit from '../views/AddOrEdit.vue'
import Detail from '../views/Detail.vue'
import Email from '../views/Email.vue'
import Tel from '../views/Tel.vue'

// 路由的配置
const routes = [
  {
    path: '/home',
    component: Home,
    name: 'home'
  },
  {
    path: '/about',
    component: About,
    name: 'about',
    redirect: '/about/email',
    children: [
      {
        path: 'email',
        component: Email,
        name: 'email'
      },
      {
        path: 'tel',
        component: Tel,
        name: 'tel'
      }
    ]
  },
  {
    path: '/add',
    component: AddOrEdit,
    name: 'add'
  },
  {
    path: '/detail/:id',
    name: 'detail',
    component: Detail
  },
  {
    path: '/edit/:id',
    name: 'edit',
    component: AddOrEdit
  },
  {
    path: '/',
    redirect: '/home'
  }
]

// // 创建路由实例
// const router = createRouter({
//   history: createWebHistory(),
//   routes
// })

// export default router

export function createRouter() {
  return _createRouter({
    history: import.meta.env.SSR ? createMemoryHistory() : createWebHistory(),
    routes
  })
}
